{% extends "base.html" %}

{% block title %}Audit Files - Archive Audit System{% endblock %}

{% block content %}
<h2>Audit File Archive</h2>

<div class="card mb-4">
    <div class="card-header">
        <h5>Archive Information</h5>
    </div>
    <div class="card-body">
        <dl class="row">
            <dt class="col-sm-3">Archive ID</dt>
            <dd class="col-sm-9">{{ archive.id }}</dd>
            
            <dt class="col-sm-3">Original Path</dt>
            <dd class="col-sm-9">{{ archive.original_path }}</dd>
            
            <dt class="col-sm-3">Archive Date</dt>
            <dd class="col-sm-9">{{ archive.archive_date }}</dd>
            
            <dt class="col-sm-3">Archived By</dt>
            <dd class="col-sm-9">{{ archive.archived_by }}</dd>
            
            <dt class="col-sm-3">Description</dt>
            <dd class="col-sm-9">{{ archive.description }}</dd>
            
            <dt class="col-sm-3">File Count</dt>
            <dd class="col-sm-9">{{ archive.file_count }}</dd>
            
            <dt class="col-sm-3">Total Size</dt>
            <dd class="col-sm-9">{{ (archive.total_size / 1024)|round(1) }} KB</dd>
        </dl>
    </div>
</div>

<div class="card">
    <div class="card-header d-flex justify-content-between align-items-center">
        <h5 class="mb-0">Archive Contents</h5>
        <div>
            <input type="text" id="fileSearch" class="form-control form-control-sm" placeholder="Search files...">
        </div>
    </div>
    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-striped table-hover" id="filesTable">
                <thead>
                    <tr>
                        <th>Path</th>
                        <th>Type</th>
                        <th>Size</th>
                        <th>Hash</th>
                    </tr>
                </thead>
                <tbody>
                    {% for file in files %}
                    <tr>
                        <td>{{ file.relative_path }}</td>
                        <td>{{ file.file_type or 'Unknown' }}</td>
                        <td>{{ (file.file_size / 1024)|round(1) }} KB</td>
                        <td>
                            <span class="hash-value text-truncate d-inline-block" style="max-width: 150px;" title="{{ file.hash }}">
                                {{ file.hash }}
                            </span>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}

{% block extra_js %}
<script>
document.addEventListener('DOMContentLoaded', function() {
    const searchInput = document.getElementById('fileSearch');
    const table = document.getElementById('filesTable');
    const rows = table.querySelectorAll('tbody tr');
    
    searchInput.addEventListener('keyup', function() {
        const query = this.value.toLowerCase();
        
        rows.forEach(row => {
            const path = row.cells[0].textContent.toLowerCase();
            const type = row.cells[1].textContent.toLowerCase();
            
            if (path.includes(query) || type.includes(query)) {
                row.style.display = '';
            } else {
                row.style.display = 'none';
            }
        });
    });
});
</script>
{% endblock %}
